package com.woniuxy.dead;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.woniuxy.utils.Utils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

public class DelayConsume {
    //声明业务交换机 业务队列  业务队列没有消费者
    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = Utils.getConnection();
        Channel channel = connection.createChannel();
        //声明业务交换机
        channel.exchangeDeclare("delayExchange", BuiltinExchangeType.DIRECT);
        Map<String,Object> map=new HashMap<>();
        //这些key值 是固定的
        map.put("x-message-ttl",20000);  //20s后过期
        map.put("x-dead-letter-exchange","deadExchange");
        map.put("x-dead-letter-routing-key","dead1");
        //声明业务队列  业务队列配置死信交换机
        channel.queueDeclare("dalayQueue",false,false,false,map);
        //业务交换机绑定队列
        channel.queueBind("dalayQueue","delayExchange","dalay1");
        //业务队列 不能绑定消费者
    }
}
